package com.fastCms.manager.bim.controller;


import com.fastCms.business.bim.pojo.po.ChangeStatusPO;
import com.fastCms.business.frame.exception.BusinessException;
import com.fastCms.business.frame.pojo.PageParam;
import com.fastCms.business.frame.pojo.po.IdStrPO;
import com.fastCms.business.frame.pojo.po.NewsQueryPO;
import com.fastCms.business.frame.pojo.po.NewsSavePO;
import com.fastCms.business.frame.pojo.vo.NewsVO;
import com.fastCms.business.frame.response.ApiResponse;
import com.fastCms.business.frame.response.ResponseUtil;
import com.fastCms.business.frame.service.NewsService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 新闻资讯 前端控制器
 * </p>
 *
 * @author quan
 * @since 2024-05-23
 */
@Api(value = "NewsController", tags = "新闻资讯管理")
@RestController
@RequestMapping("/news")
public class NewsController {
    @Resource
    private NewsService newsService;

    @PostMapping("/showPage")
    @ApiOperation(value = "列表-分页", notes = "根据业务场景筛选轮播图 scene: NEWS_WXMINI_INDEX - 微信小程序首页咨询")
    public ApiResponse<PageInfo<NewsVO>> showPage(@RequestBody PageParam<NewsQueryPO> param) {
        PageInfo<NewsVO> result = newsService.showPage(param);
        return ResponseUtil.success(result);
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "新建或更新", notes = "")
    public ApiResponse<Boolean> saveOrUpdate(@RequestBody NewsSavePO param) throws BusinessException {
        Boolean result = newsService.saveOrUpdate(param);
        return ResponseUtil.success(result);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除", notes = "根据主键ID删除")
    public ApiResponse<Boolean> delete(@RequestBody IdStrPO param) throws BusinessException {
        Boolean result = newsService.delete(param);
        return ResponseUtil.success(result);
    }

    @PostMapping("/changeStatus")
    @ApiOperation(value = "改变状态", notes = "1-展示 0-不展示")
    public ApiResponse<Boolean> changeStatus(@RequestBody ChangeStatusPO param) throws BusinessException {
        Boolean result = newsService.changeStatus(param);
        return ResponseUtil.success(result);
    }
}

